package com.yinuo.starter.config;

import com.yinuo.starter.factory.ProducerFactory;
import com.yinuo.starter.properties.ConsumerProperties;
import com.yinuo.starter.properties.JmsProperties;
import com.yinuo.starter.properties.ProducerProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.annotation.Resource;

@Configuration
@EnableConfigurationProperties({JmsProperties.class, ProducerProperties.class, ConsumerProperties.class})
public class TransactionalAutoConfigure {

    @Resource
    private JmsProperties jmsProperties;

    @Resource
    private ProducerProperties producerProperties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "yinuo.translation.producer", value = "enabled", havingValue = "true")
    ProducerFactory producerFactory(){
        return new ProducerFactory(jmsProperties, producerProperties);
    }

}
